/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package buttonexample;


import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author anxiao chen
 */
public class MyButtonPanel extends JPanel  {
       public ImageIcon i1 = new ImageIcon("F:/1.jpg"); 
       public ImageIcon i2 = new ImageIcon("F:/2.jpg"); 
       public ImageIcon i3 = new ImageIcon("F:/3.jpg"); 
       public ImageIcon i4 = new ImageIcon("F:/4.jpg");
       public ImageIcon i5 = new ImageIcon("F:/5.jpg");

      

 
    
    
    JButton quitButton = new JButton("Quit");
     JButton b1 = new JButton("home page");
     JButton b2 = new JButton("item2");
     JButton b3 = new JButton("item3");
    ButtonListener buttonListener = new ButtonListener();
  

    
    public MyButtonPanel() {
         add(quitButton);
         add(b1);
         add(b2);
         add(b3);
        
        
        quitButton.addActionListener(buttonListener);
        b1.addActionListener(buttonListener);
    
    
                b2.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
                                   //这个就是共用的代码 可以插入多图 
                               Button a=new Button("BUY");
                               Button a1=new Button("BUY");
                               Button a2=new Button("BUY");
                               Button a3=new Button("BUY");
                               Button a4=new Button("BUY");
                             
                            JFrame f1 = new JFrame();
                            JPanel j=new JPanel(new FlowLayout(FlowLayout.CENTER,20,150));
                            f1.setTitle("Goods list,buy you want!");                           
                            
                           JLabel l=new JLabel(i1);
                           j.add(l);
                           j.add(a); 
                           setLayout(new GridLayout(10,10,2,1)); 
                           f1.add(j);
                
                           JLabel l0=new JLabel(i2);
                           j.add(l0);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);  
                           j.add(a1);  
                             
                           JLabel l1=new JLabel(i3);
                           j.add(l1);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);
                           j.add(a2); 
                             
                           JLabel l2=new JLabel(i4);
                           j.add(l2);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);
                           j.add(a3); 
                             
                           JLabel l3=new JLabel(i5);
                           j.add(l3);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);  
                           j.add(a4); 
                            
                            

                           f1.setSize(800,800);
                           f1.setVisible(true);
                    
}
                        
			public void mouseEntered(MouseEvent e) {}
			public void mouseExited(MouseEvent e) {}
			public void mousePressed(MouseEvent e) {}
			public void mouseReleased(MouseEvent e) {}
		});
    
   
                
                     b3.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
                                   //这个就是共用的代码 可以插入多图 
                               Button a=new Button("BUY");
                               Button a1=new Button("BUY");
                               Button a2=new Button("BUY");
                               Button a3=new Button("BUY");
                               Button a4=new Button("BUY");
                             
                            JFrame f1 = new JFrame();
                            JPanel j=new JPanel(new FlowLayout(FlowLayout.CENTER,20,150));
                            f1.setTitle("Goods list,buy you want!"); 
                            
                           JLabel l=new JLabel(i1);
                           j.add(l);
                           j.add(a); 
                           setLayout(new GridLayout(10,10,2,1)); 
                           f1.add(j);
                
                           JLabel l0=new JLabel(i2);
                           j.add(l0);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);  
                           j.add(a1);  
                             
                           JLabel l1=new JLabel(i3);
                           j.add(l1);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);
                           j.add(a2); 
                             
                           JLabel l2=new JLabel(i4);
                           j.add(l2);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);
                           j.add(a3); 
                             
                           JLabel l3=new JLabel(i5);
                           j.add(l3);
                           setLayout(new GridLayout(0,10,2,1)); 
                           f1.add(j);  
                           j.add(a4); 
                            
                            

                           f1.setSize(800,800);
                           f1.setVisible(true);
                    
}
                        
			public void mouseEntered(MouseEvent e) {}
			public void mouseExited(MouseEvent e) {}
			public void mousePressed(MouseEvent e) {}
			public void mouseReleased(MouseEvent e) {}
		});
                
                
                
    
    }

    private final class ButtonListener implements ActionListener {
      

        public ButtonListener() {
        }

        public void actionPerformed(ActionEvent e) {
         
        
            if (e.getActionCommand().equals("Quit")) {
                System.exit(1);
            }
            
            else if(e.getActionCommand().equals("home page")){
                Runtime rt= Runtime.getRuntime(); 
                try {
                    Process proc= rt.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe www.ica.se");
              } catch (IOException ex) {
                    Logger.getLogger(MyButtonPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}
       
    
   

    
    




